package com.yixun.lbx.service.impl;

import com.yixun.lbx.service.LbxRedisService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class LbxRedisServiceImpl implements LbxRedisService {
    private final RedisTemplate<String, Object> redisTemplate;

    public LbxRedisServiceImpl(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public Long incr(String key) {
        return redisTemplate.opsForValue().increment(key);
    }

    public void setKeyIncrValue(String key, Integer value) {
        redisTemplate.opsForValue().set(key, value);
    }

    @Override
    public String getKey(String key) {
        return String.valueOf(redisTemplate.opsForValue().get(key));
    }

    @Override
    public void setKeyValue(String key, String value) {
        redisTemplate.opsForValue().set(key, value);

    }

    @Override
    public Boolean deleteKey(String key) {
        return redisTemplate.delete(key);
    }


    public Set<String> getTimers(String pix) {
        return redisTemplate.keys(pix + "*");
    }


}
